package com.freemaster.sys.service.impl;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.util.StringUtils;
import com.freemaster.sys.entity.Resource;
import com.freemaster.sys.mapper.ResourceMapper;
import com.freemaster.sys.service.ResourceService;

@Service
@Transactional(readOnly = false)
public class ResourceServiceImpl implements ResourceService {

	
	@Autowired
	ResourceMapper resourceMapper;
	
	@Override
	public Set<String> findPermissions(Set<Long> resourceIds) {
		Set<String> permissions = new HashSet<String>();
		for (Long resourceId : resourceIds) {
			Resource resource = findOne(resourceId);
			if (resource != null && !StringUtils.isEmpty(resource.getPermission())) {
				permissions.add(resource.getPermission());
			}
		}

		return permissions;
	}

	@Override
	public Resource findOne(Long resourceId) {
		// TODO Auto-generated method stub
		return resourceMapper.findOne(resourceId);
	}

}
